package com.mtt.thirdapi.oujian.controller;

import com.alibaba.fastjson.JSONObject;
import com.mtt.thirdapi.common.api.R;
import com.mtt.thirdapi.common.api.ResultCode;
import com.mtt.thirdapi.common.exception.MttErpException;
import com.mtt.thirdapi.oujian.config.OjConfig;
import com.mtt.thirdapi.oujian.util.OJApiUtils;
import com.mtt.thirdapi.oujian.vo.OjApiOrdersVo;
import com.mtt.thirdapi.oujian.vo.OjRequestUrlVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 欧坚服务接口
 */
@RestController
@RequestMapping("oujian")
@Slf4j
@Validated
public class OJController {

    @PostMapping("requestPdfUrl")
    @ApiOperation(value = "获取电子面单",notes = "获取电子面单")
    public R queryRequestPdfUrl(OjRequestUrlVo ojRequestUrlVo){
        try{
            String JsonRequestDate = JSONObject.toJSONString(ojRequestUrlVo);
            String data = OJApiUtils.httpPostWithJSON(OjConfig.requestPdfUrl, JsonRequestDate);
            return R.data(data);
        }catch(Exception e){
            return R.fail(ResultCode.FAILURE);
        }
    }
    @PostMapping("products")
    @ApiOperation(value = "获取渠道信息",notes = "获取配置好的发送渠道")
    public R queryProducts(){
        try{
            String data = OJApiUtils.httpPostWithJSON(OjConfig.products, null);
            return R.data(data);
        }catch(Exception e){
            return R.fail(ResultCode.FAILURE);
        }
    }
    @PostMapping("orders")
    @ApiOperation(value = "在线下单",notes = "在线下单")
    public R queryOrders(@RequestBody OjApiOrdersVo[] ojApiOrdersVo){
        try{
            JSONObject jsonParam = new JSONObject();
            jsonParam.put("apiOrders",ojApiOrdersVo);
            String JsonRequestDate = JSONObject.toJSONString(jsonParam);
            String data = OJApiUtils.httpPostWithJSON(OjConfig.orders, JsonRequestDate);
            return R.data(data);
        }catch(Exception e){
            return R.fail(ResultCode.FAILURE);
        }
    }
}
